home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: What is &Variable (declared as: char Variable[10])?
- Date: 27 Feb 1996 11:23:33 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4gvlnlINNppj@anvil.ugrad.cs.ubc.ca>
- References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <4gsdno$1bg@umbc9.umbc.edu>,
- Jonas J. Schlein <schlein@umbc.edu> wrote:
- >Abu Wawda <wawda@alcor.usc.edu> wrote:
- >|> I'm having trouble understanding what the address of a static array
- >|> is.
- >
- >I'm having trouble understanding why it matters? You almost never use the
- >address of an array directly unless doing something tricky with pointers
- >or with particular dimensions of a multiple dimensional array.
-
- Not necessarily. The address of an array is very useful in abstracting away the
- representation of a variable that happens to be represented as an array. This
- is nothing tricky.
-
- For example, the LibDES encryption library defines a type:
-
- typedef char des_cblock[8];
-
- which can hold DES cipherblocks (such as hashed keys). The LibDES routines take
- pointers to this type, which effectively hides its representation. The client
- can declare a variable of type des_cblock without caring whether it is a
- struct, double, long, array or union. When passing it to a LibDES library
- routine, it will take the address. Unless the code is poorly writte,
- the fact that the variable is actually an array (and hence its name is an
- expression which collapses into a pointer to the first element of an array and
- is not a modifiable lvalue) is never taken advantage of.
-
- The benefit is that (1) the compiler can typecheck that what is being
- passed is in fact a pointer to an array of 10 chars, as expected by the
- prototype---if des_cblock was a pointer to char, you would not be able to have
- this sort of check---and (2) the representation of des_cblock could be changed
- to something else without affecting well-behaved client code that doesn't
- assume that des_cblock objects can be passed by value to internal routines or
- can be assigned.
- --
-
-